package x.y.z;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import x.y.z.repository.KeyValDao;

import javax.annotation.Resource;

@SpringBootApplication
@Slf4j
public class JdbcTemplateApp implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(JdbcTemplateApp.class, args);
    }

    @Autowired
    KeyValDao dao;

    @Resource
    ObjectMapper mapper;

    @Override
    public void run(String... args) throws Exception {
        dao.all().stream().map(o->{
            try {
                return mapper.writeValueAsString(o);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            return null;
        }).forEach(log::info);
    }
}
